home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / anivga12 / example4.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-07-11  |  1.6 KB  |  60 lines

  1. {$A+,B-,D+,L+,N-,E-,O-,R-,S-,V-,G-,F-,I-,X-}
  2. {$M 16384,0,655360}
  3. PROGRAM Example4;
  4.  
  5. {Demonstrates use of sprite cycles & SetCycleTime() to control animation speed}
  6. {Besides that, usage of a sprite library is shown}
  7.  
  8. USES ANIVGA,CRT;
  9. CONST LoadHantel=1;
  10.       SpriteName='HANTEL.LIB'; {Path and name of the sprite to load}
  11.       flip:BOOLEAN=FALSE;      {Flag for animation speed}
  12.       ch:Char=#0;
  13. VAR PicsLoaded:BYTE;
  14.     i,n:WORD;
  15.  
  16. BEGIN
  17.  PicsLoaded:=loadSprite(SpriteName,LoadHantel); {load sprites}
  18.  IF Error<>Err_None
  19.   THEN BEGIN
  20.         CloseRoutines;
  21.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  22.         halt(1)
  23.        END;
  24.  SetSpriteCycle(LoadHantel,PicsLoaded); {cycle through all images endlessly}
  25.  
  26.  InitGraph;
  27.  
  28.  FillBackground(76);
  29.  
  30.  FOR i:=1 TO 100 DO  {choose app. 100 sprites}
  31.   BEGIN
  32.    n:=RANDOM(NMAX)+1;
  33.    SpriteN[n]:=LoadHantel+RANDOM(PicsLoaded);  {enter cycle somewhere}
  34.    SpriteX[n]:=RANDOM(XMAX+1);  {use a random coordinates}
  35.    SpriteY[n]:=RANDOM(YMAX+1)
  36.   END;
  37.  
  38.  REPEAT
  39.   IF KeyPressed
  40.    THEN BEGIN
  41.          ch:=UpCase(ReadKey);
  42.          CASE ch OF
  43.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  44.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  45.           'D':inc(StartVirtualX,10);
  46.           'X':inc(StartVirtualY,10);
  47.           ' ':BEGIN   {toggle speed between maximum and 200ms per frame}
  48.                flip:=NOT flip;
  49.                IF flip
  50.                 THEN SetCycleTime(200)
  51.                 ELSE SetCycleTime(0)
  52.               END;
  53.          END;
  54.         END;
  55.   Animate;
  56.  UNTIL (ch='Q') OR (ch=#27);
  57.  
  58.  CloseRoutines;
  59. END.
  60.